Page({
  data:{
    list: [
     
    ],
    alpha: '',
    windowHeight: '',
    inputValue: '',
    isTrue: true
  }, bindinput: function (e) {
    var that = this;
    var ss = e.detail.value
    wx.request({
      url: 'http://localhost:8080/like?str=' + ss,
      method: 'GET',

      success: function (res) {
        var seachdata = res.data.UserInfoList;
        console.log(seachdata)
        if (seachdata == null) {
          that.setData({
            list: seachdata,
            isTrue: false
          })

        } else {
          that.setData({
            list: seachdata,
            isTrue: true
          })
        }
      }
    })
  },

  click_handler:function(event){
    console.log("click_handler")
    var _opid = event.currentTarget.dataset.opid
    wx.request({
      url: 'http://localhost:8080/UserCard/findByUserId2?userId=' + _opid,
      method:"GET",
      data:{},
      success:function(res){
        var isExist = res.data.isExist;
        if (!isExist){
          wx.showToast({
            title: '请去建立名片',
            icon: 'none',
            duration: 2000
          })
        }else{
          wx.navigateTo({
            url: '../scCard/scCard?opid=' + _opid,
            success: function (res) {
              // success
              console.log(_opid)
            },
            fail: function () {
              // fail
              console.log(_opid)
            },
            complete: function () {
              // complete
            }
          })
        }
      }
    })
    
  },
  onLoad:function(options){
    var that = this;
    wx.request({
      url: 'http://localhost:8080/findAll',
      method: 'POST',
      data: {},
      success: function (res) {
        var list = res.data.userInfoList;
        if (list == null) {
          var toastText = '获取数据失败' + res.data.errMsg;

        } else {
          that.setData({
            list: list
          })
        }
      }
    })
    try {
      var res = wx.getSystemInfoSync()
      this.pixelRatio = res.pixelRatio;
      // this.apHeight = 32 / this.pixelRatio;
      // this.offsetTop = 160 / this.pixelRatio;
      this.apHeight = 16;
      this.offsetTop = 80;
      this.setData({windowHeight: res.windowHeight + 'px'})
    } catch (e) {
      
    }
  },
  onPullDownRefresh :function(){
    var that = this;
    wx.request({
      url: 'http://localhost:8080/findAll',
      method: 'POST',
      data: {},
      success: function (res) {
        var list = res.data.userInfoList;
        if (list == null) {
          var toastText = '获取数据失败' + res.data.errMsg;

        } else {
          that.setData({
            list: list,
            isTrue:true
          })
        }
      }
    })
    //当逻辑执行完后关闭刷新    
    wx.stopPullDownRefresh()
  },
  handlerAlphaTap(e) {
    let {ap} = e.target.dataset;
    this.setData({alpha: ap});
  },
  handlerMove(e) {
    let {list} = this.data;
    let moveY = e.touches[0].clientY;
    let rY = moveY - this.offsetTop;
    if(rY >= 0) {
      let index = Math.ceil((rY - this.apHeight)/ this.apHeight);
      if(0 <= index < list.length) {
        let nonwAp = list[index];
        nonwAp && this.setData({alpha: nonwAp.alphabet});
      } 
    }
  }
})